package com.tjjingpan.wifidirectdemo.callback

import android.app.Activity
import android.app.Service
import android.content.Intent
import android.widget.Toast
import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.AppCompatActivity
import com.tjjingpan.wifidirectdemo.widget.LoadingDialog

open class BaseActivity : AppCompatActivity() {

    var loadingDialog: LoadingDialog? = null

    fun setTitle(title: String?) {
        val actionBar: ActionBar? = getSupportActionBar()
        if (actionBar != null) {
            actionBar.setTitle(title)
        }
    }

    fun showLoadingDialog(message: String?) {
        if (loadingDialog == null) {
            loadingDialog = LoadingDialog(this)
        }
        loadingDialog!!.show(message, true, false)
    }

    fun dismissLoadingDialog() {
        loadingDialog?.dismiss()
    }

    fun <T : Activity?> startActivity(tClass: Class<T>?) {
        startActivity(Intent(this, tClass))
    }

    fun <T : Service?> startService(tClass: Class<T>?) {
        startService(Intent(this, tClass))
    }

    fun showToast(message: String?) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
    }
}

